package net.airtheva.uniqueTask5;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class AddLocationDialog extends DialogFragment {

	public static final String TAG = "AddLocationDialog";
	
	EditText mLocationName;
	
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle(TAG);
		View view = ((LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.fragment_add_location, null);
		
		mLocationName = (EditText) view.findViewById(R.id.fragment_add_location_locationName);
		
		builder.setView(view);
		builder.setPositiveButton("添加", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
				Toast.makeText(getActivity(), mLocationName.getText().toString(), Toast.LENGTH_SHORT).show();
				
				WeatherActivity weatherActivity = (WeatherActivity) getActivity();
				weatherActivity.AddLocation(mLocationName.getText().toString());
				
			}
		});
		builder.setNegativeButton("放弃", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
			}
		});
		
		return builder.create();
	}

	
	
}
